package cn.nsu.douban.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import cn.nsu.douban.dao.dao.IActorDao;
import cn.nsu.douban.entity.ActorInfo;
import cn.nsu.douban.entity.MovieInfo;

@Repository
public class IActorDaoImpl extends HibernateDaoSupport  implements IActorDao{
 
	@Resource
	public void setSessionFacctory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}

	@Override
	public ActorInfo getActorByMovieInfo(MovieInfo movieInfo) {
  
		String hqlString="select s from MovieInfo m  join m.ac s where m.id=?";
		@SuppressWarnings("unchecked")
		List<ActorInfo> actorInfos = this.getHibernateTemplate().find(hqlString, movieInfo.getId());
		
		return actorInfos.get(0);
	}

	@Override
	public List<ActorInfo> getAll() {

		return this.getHibernateTemplate().find("from ActorInfo");
	} 
	
	
}
